import React, { Component } from 'react'
import { connect } from 'dva';
import Link from 'umi/link';
import { Form, Input } from 'antd';
import { SearchRow, SearchCol, SearchButton } from '@/styled/form';

interface IProps {
  dispatch?: ({ type }: { type: string, payload?: any }) => Promise<any>;
  current?: number;
  form: any;
  setShow: Function;
  initCurrent?: Function;
  new?: boolean;
  dict?: any;
  cond?: any;
}

const FormItem = Form.Item;

@connect(({ task_month }) => ({
  cond: task_month.taskCond,
}))
class Target extends Component<IProps, any> {

  search = e => {
    e.preventDefault();
    const { dispatch, form, initCurrent } = this.props;
    form.validateFields((err, values) => {
      if (!err) {
        dispatch({
          type: 'task_month/updateTargetCond',
          payload: {
            ...values
          }
        })
        initCurrent()
      }
    });
  }

  addFloor = e => {
    e.preventDefault();
    this.props.setShow();
  }

  render() {
    const { form } = this.props;
    const { getFieldDecorator } = form;
    const formItemLayout = {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    };
    return (
      <Form onSubmit={this.search}>
        <SearchRow>
          {/* <SearchCol key={0} span={5}>
            <FormItem
              label="检查内容"
              {...formItemLayout}
            >
              {getFieldDecorator('name', {
                rules: [{ message: '检查内容' }],
              })(
                <Input style={{ width: '100%' }} placeholder="检查内容" />
              )}
            </FormItem>
          </SearchCol> */}
          <SearchCol key={3} span={24}>
            <SearchRow type="flex" justify="end">
              {/* <SearchButton htmlType="submit">搜索</SearchButton> */}
              <Link to='/data/task_month/new'>
                <SearchButton type="primary" onClick={this.addFloor}>添加楼层</SearchButton>
              </Link>
            </SearchRow>
          </SearchCol>
        </SearchRow>
      </Form>
    );
  }
}

const TargetS = Form.create<IProps>()(Target);
export default TargetS;
